home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
PredatorPrey
/
ZEquals.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
14KB
|
492 lines
/* ZEquals.c -- Modal dialog */
/* Created 940321 20:45 by AppMaker */
#include <Types.h>
#include <Quickdraw.h>
#include <Controls.h>
#include <Dialogs.h>
#include <Events.h>
#include <Lists.h>
#include <Menus.h>
#include <TextEdit.h>
#include "ResourceDefs.h"
#include "Miscellany.h"
#include "DialogAids.h"
#include "WindowAids.h"
#include "ZEquals.h"
#include "ErrorWindow.h"
#include <AppleEvents.h>
//#include <EPPC.h>
#include <PPCToolbox.h>
#include <Aliases.h>
#include <Files.h>
#include <Processes.h>
#include "calc_mousedown.h"
#define kFinderType 'FNDR'
#define kSysCreator 'MACS'
#define kAEOpenSelection 'sope'
#define aeSelectionKeyword 'fsel'
#define OKButton 1
#define CancelButton 2
#define ZLabel 3
#define Field4 4 /* Y1 text */
#define ZEQUALSLabel 5
#define Button6 6 /* ^ */
#define Button7 7 /* / */
#define Button8 8 /* * */
#define Button9 9 /* - */
#define Button10 10 /* + */
#define Button11 11 /* π */
#define eButton 12 /* e^ */
#define LogButton 13 /* Log */
#define LnButton 14 /* Ln */
#define SinButton 15 /* Sin */
#define CosButton 16 /* Cos */
#define TanButton 17 /* Tan */
#define ArcTanButton 18 /* ArcTan */
#define ArcSinButton 19 /* ArcSin */
#define ArcCosButton 20 /* ArcCos */
#define x10Button 21 /* 10^ */
#define Button22 22 /* √ */
#define Button23 23 /* ( */
#define Button24 24 /* ) */
#define qButton 25 /* theta */
#define x7Button 26 /* 7 */
#define x8Button 27 /* 8 */
#define x9Button 28 /* 9 */
#define x4Button 29 /* 4 */
#define x5Button 30 /* 5 */
#define x6Button 31 /* 6 */
#define x1Button 32 /* 1 */
#define x2Button 33 /* 2 */
#define x0Button 34 /* 0 */
#define Button35 35 /* decimal point */
#define x3Button 36 /* 3 */
#define xxButton 37 /* x */
#define ChkSynButton 38 /* check syntax */
#define SelTgt 39 /* select target */
OSErr FindAProcess (
OSType typeToFind,
OSType creatorToFind,
ProcessSerialNumberPtr processSN,
ProcessInfoRecPtr infoRecToFill
);
static void DoChkSynButton ( short lastItem, ZEqualsRec *ZEquals, DialogPtr theDialog);
/*----------*/
static void DoChkSynButton ( short lastItem, ZEqualsRec *ZEquals, DialogPtr theDialog)
{
short i,j,k,m;
WindowPtr errorWin;
ZEqualsRecPtr info;
StringHandle message;
Point thePt;
Rect Z1Rect;
info = ZEquals;
j = 0;
k = 0;
m = 0;
SetRect(&Z1Rect,190,4,380,22);
switch(lastItem)
{
case 4:
MoveTo(4,0);
for(i = 1;i <= info->Field4Text[0];i++)
{
if(info->Field4Text[i] == '(') j++;
if(info->Field4Text[i] == ')') k++;
}
break;
}
if( j == k ) ; /* do nothing */
else
{
m++;
Move(0,m * 18);
GetPen(&thePt);
switch(lastItem)
{
case 4:
EraseRect(&Z1Rect);
BlockMove("\pIn the Z1 = field, there ",cur->Field3Handle,25);
/*DrawString("\pIn the Z1 = field, there ");*/
break;
}
if(j - k >= 2)
{
BlockMove("\pare ",cur->Field3Handle,4);
/*DrawString("\pare ");*/
message = GetString(3001); /* too many occurences of '\(' */
BlockMove(*message,cur->Field3Handle,GetHandleSize((Handle) message));
/*DrawString(*message);*/
MoveTo(thePt.h,thePt.v);
}
else if(j - k == 1 || k - j == 1)
{
BlockMove("\pis ",cur->Field3Handle,3);
/* DrawString("\pis ");*/
message = GetString(3002); /* no '\)' found to match '\(' */
BlockMove(*message,cur->Field3Handle,GetHandleSize((Handle) message));
/*DrawString(*message);*/
MoveTo(thePt.h,thePt.v);
}
else if(k - j >=2)
{
BlockMove("\pare ",cur->Field3Handle,4);
/* DrawString("\pare ");*/
message = GetString(3000); /* too many occurences of '\)' */
BlockMove(*message,cur->Field3Handle,GetHandleSize((Handle) message));
/*DrawString(*message);*/
MoveTo(thePt.h,thePt.v);
}
}
} /*DoChkSynButton*/
/*----------*/
Boolean GetZEquals (ZEqualsRec *ZEquals)
{
DialogPtr theDialog;
GrafPtr savePort,save2Port;
Boolean result;
Boolean done;
short itemNr;
register ZEqualsRecPtr info;
short i,lastItem;
TEHandle dialogTE;
WindowPtr saveCur,errorCur;
WindowPtr errorWin = nil;
ModalFilterUPP gMyStandardFilterUPP;
OSErr iErr;
AEEventClass theAEEventClass;
AEEventID theAEEventID;
AppleEvent theResult;
DescType typeCode;
LocationNameRec theLocation;
PortInfoRec thePortInfo;
TargetID theID;
AEDesc myAddressDesc;
AppleEvent aeEvent, aeReply;
FSSpecPtr theFileToOpen = nil;
FSSpec dirSpec, procSpec;
AliasHandle DirAlias, FileAlias;
ProcessSerialNumber process;
ProcessInfoRec infoRec;
StandardFileReply myReply;
Str31 processName;
AEDesc aeDirDesc, listElem;
AEDesc fileList;
lastItem = 4;
GetPort (&savePort);
InitCursor ();
theDialog = GetNewDialog (ZEqualsID, nil, (WindowPtr) -1L);
SetPort (theDialog);
info = ZEquals;
SetDText (Field4, info->Field4Text);
ShowWindow (theDialog);
OutlineButton (1);
gMyStandardFilterUPP = NewModalFilterProc(StandardFilter); /* new */
done = false;
while (!done) {
//ModalDialog (StandardFilter, &itemNr);
ModalDialog(gMyStandardFilterUPP,&itemNr);
dialogTE = ( (DialogPeek)theDialog)->textH;
switch (itemNr) {
case OKButton:
result = true;
done = true;
break;
case CancelButton:
result = false;
done = true;
break;
case Field4:
GetDText (itemNr, info->Field4Text);
lastItem = itemNr;
break;
case Button6:
TEKey(94,dialogTE); /* ^( */
TEKey(40,dialogTE);
/* TEKey forces an update after every */
/* key, whereas SetIText will let you */
/* blast a bunch of chars to the field */
/* before the update */
break;
case Button7:
TEKey(47,dialogTE); /* / */
break;
case Button8:
TEKey(42,dialogTE); /* * */
break;
case Button9:
TEKey(45,dialogTE); /* - */
break;
case Button10:
TEKey(43,dialogTE); /* + */
break;
case Button11:
TEKey(185,dialogTE); /* π */
break;
case eButton:
TEKey(101,dialogTE); /* e^( */
TEKey(94,dialogTE);
TEKey(40,dialogTE);
break;
case LogButton:
TEKey(76,dialogTE); /* Log( */
TEKey(111,dialogTE);
TEKey(103,dialogTE);
TEKey(40,dialogTE);
break;
case LnButton:
TEKey(76,dialogTE); /* Ln( */
TEKey(110,dialogTE);
TEKey(40,dialogTE);
break;
case SinButton:
TEKey(83,dialogTE); /* Sin( */
TEKey(105,dialogTE);
TEKey(110,dialogTE);
TEKey(40,dialogTE);
break;
case CosButton:
TEKey(67,dialogTE); /* Cos( */
TEKey(111,dialogTE);
TEKey(115,dialogTE);
TEKey(40,dialogTE);
break;
case TanButton:
TEKey(84,dialogTE); /* Tan( */
TEKey(97,dialogTE);
TEKey(110,dialogTE);
TEKey(40,dialogTE);
break;
case ArcTanButton:
TEKey(65,dialogTE); /* ArcTan( */
TEKey(114,dialogTE);
TEKey(99,dialogTE);
TEKey(84,dialogTE);
TEKey(97,dialogTE);
TEKey(110,dialogTE);
TEKey(40,dialogTE);
break;
case ArcSinButton:
TEKey(65,dialogTE); /* ArcSin( */
TEKey(114,dialogTE);
TEKey(99,dialogTE);
TEKey(83,dialogTE);
TEKey(105,dialogTE);
TEKey(110,dialogTE);
TEKey(40,dialogTE);
break;
case ArcCosButton:
TEKey(65,dialogTE); /* ArcCos( */
TEKey(114,dialogTE);
TEKey(99,dialogTE);
TEKey(67,dialogTE);
TEKey(111,dialogTE);
TEKey(115,dialogTE);
TEKey(40,dialogTE);
break;
case x10Button:
TEKey(49,dialogTE); /* 10^( */
TEKey(48,dialogTE);
TEKey(94,dialogTE);
TEKey(40,dialogTE);
break;
case Button22:
TEKey(195,dialogTE); /* √ */
TEKey(40,dialogTE);
break;
case Button23:
TEKey(40,dialogTE); /* ( */
break;
case Button24:
TEKey(41,dialogTE); /* ) */
break;
case qButton:
TEKey(84,dialogTE); /* theta */
TEKey(104,dialogTE);
TEKey(101,dialogTE);
TEKey(116,dialogTE);
TEKey(97,dialogTE);
break;
case x7Button:
TEKey(55,dialogTE); /* 7 */
break;
case x8Button:
TEKey(56,dialogTE); /* 8 */
break;
case x9Button:
TEKey(57,dialogTE); /* 9 */
break;
case x4Button:
TEKey(52,dialogTE); /* 4 */
break;
case x5Button:
TEKey(53,dialogTE); /* 5 */
break;
case x6Button:
TEKey(54,dialogTE); /* 6 */
break;
case x1Button:
TEKey(49,dialogTE); /* 1 */
break;
case x2Button:
TEKey(50,dialogTE); /* 2 */
break;
case x0Button:
TEKey(48,dialogTE); /* 0 */
break;
case Button35:
TEKey(46,dialogTE); /* decimal point */
break;
case x3Button:
TEKey(51,dialogTE); /* 3 */
break;
case xxButton:
TEKey(120,dialogTE); /* x */
break;
case ChkSynButton:
GetDText (4, info->Field4Text);
GetPort(&save2Port); /* GrafPtr save2Port; */
/*saveCur = curWindow;*/ /* WindowPtr saveCur; */
if(errorWin == nil)
{
errorWin = OpenErrorWindow ("\p", 0, 0); /*OpenErrorWindow (fName, vRefNum, fRefNum);*/
/*SetPort(errorWin);*/
/*errorCur = curWindow;*/
/*SelectWindow(errorWin);*/
}
else
{
SetPort(errorWin);
}
DoChkSynButton ( 4/*lastItem*/ , ZEquals, theDialog);
/*SetInfo (saveCur);*/
SetPort(save2Port);
SelectWindow((WindowPtr)save2Port);
break;
case SelTgt:
/*****************************/
GetPort(&save2Port);
StandardGetFile(nil, -1, nil, &myReply);
#ifdef DEBUGGING
DebugStr("\pRight after StandardGetFile");
#endif
if (myReply.sfGood)
{
#ifdef DEBUGGING
DebugStr("\pRight before theFileToOpen");
#endif
theFileToOpen = &myReply.sfFile;
infoRec.processInfoLength = sizeof(ProcessInfoRec);
infoRec.processName = &processName[0];
infoRec.processAppSpec = &procSpec;
#ifdef DEBUGGING
DebugStr("\pRight before FindAProcess");
#endif
iErr = FindAProcess(kFinderType, kSysCreator, &process, &infoRec);
#ifdef DEBUGGING
DebugStr("\pRight after FindAProcess");
#endif
if (iErr == noErr)
iErr = AECreateDesc(typeProcessSerialNumber, (Ptr)&process, sizeof(process), &myAddressDesc);
#ifdef DEBUGGING
DebugStr("\pRight after AECreateDesc");
#endif
if (iErr == noErr)
{
iErr = AECreateAppleEvent (
kFinderType, kAEOpenSelection,
&myAddressDesc, kAutoGenerateReturnID,
kAnyTransactionID, &aeEvent
);
AEDisposeDesc(&myAddressDesc);
#ifdef DEBUGGING
DebugStr("\pRight after AECreateAppleEvent");
#endif
if (iErr == noErr)
{
iErr = FSMakeFSSpec(theFileToOpen->vRefNum, theFileToOpen->parID, nil, &dirSpec);
NewAlias(nil, &dirSpec, &DirAlias);
NewAlias(nil, theFileToOpen, &FileAlias);
#ifdef DEBUGGING
DebugStr("\pRight after NewAlias");
#endif
}
if (iErr == noErr)
{
iErr = AECreateList(nil, 0, false, &fileList);
/* create the folder descriptor */
HLock((Handle)DirAlias);
AECreateDesc(typeAlias, (Ptr)*DirAlias, GetHandleSize((Handle)DirAlias), &aeDirDesc);
HUnlock((Handle)DirAlias);
if ((iErr = AEPutParamDesc(&aeEvent, keyDirectObject, &aeDirDesc)) == noErr)
{
/* done with the desc, kill it */
AEDisposeDesc(&aeDirDesc);
/* create the file descriptor and add to aliasList */
HLock((Handle)FileAlias);
AECreateDesc(typeAlias, (Ptr)*FileAlias, GetHandleSize((Handle)FileAlias), &listElem);
HLock((Handle)FileAlias);
iErr = AEPutDesc(&fileList, 0, &listElem);
}
if (iErr == noErr)
{
AEDisposeDesc(&listElem);
/* Add the file alias list to the event */
iErr = AEPutParamDesc(&aeEvent, aeSelectionKeyword, &fileList);
AEDisposeDesc(&fileList);
if (iErr == noErr)
iErr = AESend(&aeEvent, &aeReply, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
kAENormalPriority, kAEDefaultTimeout, nil, nil);
}
}
AEDisposeDesc(&aeEvent);
}
}
SetPort(save2Port);
SelectWindow((WindowPtr)save2Port);
/*****************************/
break;
} /* switch */
} /* while */
//DisposHandle ((Handle) cur->filename);
//DiscardInfo (curWindow);
//theAEEventID = ;
//theAEEventClass = 'aevt';
//iErr = AECreateDesc(typeCode,dataPtr,dataSize,&result);
//iErr = AECreateAppleEvent(theAEEventClass,theAEEventID,&target,returnID,transactionID,&theResult);
//AESend(result);
AESend(&aeEvent, &aeReply, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
kAENormalPriority, kAEDefaultTimeout, nil, nil);
DisposDialog (theDialog);
SetPort (savePort);
return (result);
} /*GetYEquals*/
/* YEquals */